﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace DesignPattern.Prototype
{
    /// <summary>
    /// people 人类
    /// </summary>
    [Serializable]
    public class People : ICloneable
    {
        /// <summary>
        /// 姓名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 年龄
        /// </summary>
        public Int32 Age { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        public bool Sex { get; set; }

        /// <summary>
        /// 克隆，深复制
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            //浅复制
            //return this.MemberwiseClone();
            MemoryStream stream = new MemoryStream();
            BinaryFormatter format = new BinaryFormatter();
            format.Serialize(stream, this);
            stream.Position = 0;
            return format.Deserialize(stream) as People;
        }
    }
}
